from gevent import monkey
import gevent
import urllib.request

# 有IO才做时需要这一句
monkey.patch_all()


# 实现多个视频下载

def my_downLoad(file_name, url):
    print('GET: %s' % url)
    resp = urllib.request.urlopen(url)
    data = resp.read()

    with open(file_name, "wb") as f:
        f.write(data)

    print('%d bytes received from %s.' % (len(data), url))


gevent.joinall([
    gevent.spawn(my_downLoad, "1.mp3",
                 'http://byrobot-front.oss-cn-hangzhou.aliyuncs.com/%E8%83%8C%E6%99%AF%E9%9F%B3%E4%B9%90%EF%BC%88%E5%A4%9C%E7%9A%84%E9%92%A2%E7%90%B4%E6%9B%B2%E4%BA%94%EF%BC%89.mp3'),
    gevent.spawn(my_downLoad, "2.mp3",
                 'http://byrobot-front.oss-cn-hangzhou.aliyuncs.com/%E8%83%8C%E6%99%AF%E9%9F%B3%E4%B9%90%EF%BC%88%E5%A4%9C%E7%9A%84%E9%92%A2%E7%90%B4%E6%9B%B2%E4%BA%94%EF%BC%89.mp3'),
])
